home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / hyperViewer.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  9.9 KB  |  388 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  March 13, 1997
  22. //
  23. //  Description:
  24. //      This script creates a bookmarkEditor for the Hyper Graph
  25. //    as well as handling all the bookmarks for the Hyper Graph Menus
  26. //
  27. //  Input Arguments:
  28. //      parent
  29. //
  30. //  Return Value:
  31. //      None.
  32. //
  33. //
  34.  
  35.  
  36. global string $hyperBookmarks[];
  37. global int $hyperBookmarksInitialized = 0;
  38.  
  39.  
  40. global proc hyperViewer(string $editor)
  41. {
  42.     global int $hyperBookmarksInitialized;
  43.  
  44.     if (`window -exists hyperBookmarkWindow`){
  45.         showWindow hyperBookmarkWindow;
  46.         hyperBookmarkUpdate($editor);
  47.     } else {
  48.         hyperBookmarkCreateUI($editor);
  49.     }
  50.  
  51.     if (!$hyperBookmarksInitialized) {
  52.         scriptJob -parent "hyperBookmarkWindow" 
  53.             -conditionTrue "deleteAllCondition" 
  54.             ("hyperBookmarkUpdate " + $editor);
  55.         scriptJob -parent "hyperBookmarkWindow"
  56.              -disregardIndex -attributeChange hyperGraphInfo.bookmarks 
  57.             ("hyperBookmarkUpdate " + $editor);
  58.         $hyperBookmarksInitialized = 1;
  59.     }
  60. }
  61.  
  62.  
  63. global proc hyperBookmarkCreateUI(string $editor)
  64. {
  65.     // Create a new window
  66.     window
  67.         -title "Bookmarks"
  68.         -iconName "Bookmarks"
  69.         -width 150 -height 400
  70.         -menuBar true
  71.         -minimizeButton true
  72.         -maximizeButton false
  73.         hyperBookmarkWindow;
  74.  
  75.     hyperBookmarkMakeMenuBar($editor);
  76.  
  77.     formLayout hyperBookmarkEditorForm;
  78.     formLayout hyperBookmarkListForm;
  79.     setParent ..; // hyperBookmarkEditorForm;
  80.     formLayout -height 30 hyperBookmarkButtonsForm;
  81.     button -l "Create Bookmark" 
  82.         -c ("hyperBookmarkAddCallback " + $editor + " later")
  83.         addBookmarkButton;
  84.     
  85.     formLayout -e 
  86.         -attachForm hyperBookmarkListForm right 0
  87.         -attachForm hyperBookmarkListForm left 0
  88.         -attachForm hyperBookmarkListForm top 0
  89.         hyperBookmarkEditorForm;
  90.     
  91.     formLayout -e
  92.         -attachForm hyperBookmarkButtonsForm right 0
  93.         -attachForm hyperBookmarkButtonsForm left 0
  94.         -attachForm hyperBookmarkButtonsForm bottom 0
  95.         hyperBookmarkEditorForm;
  96.  
  97.     formLayout -e
  98.         -attachControl hyperBookmarkListForm bottom 0 hyperBookmarkButtonsForm
  99.         hyperBookmarkEditorForm;
  100.     
  101.     formLayout -e
  102.         -af addBookmarkButton top 0 
  103.         -af addBookmarkButton left 0 
  104.         -af addBookmarkButton bottom 0
  105.         -af addBookmarkButton right 0 
  106.         hyperBookmarkButtonsForm;
  107.  
  108.     hyperBookmarkUpdate($editor);
  109.     showWindow hyperBookmarkWindow;
  110. }
  111.  
  112.  
  113. global proc hyperBookmarkMakeMenuBar(string $editor)
  114. {
  115.     menu -l "Edit" -aob true;
  116.         menuItem 
  117.             -l "Create Bookmark"
  118.             -command ("hyperBookmarkAddCallback " + $editor + " later")
  119.              hyperBookmarkAddMenuItem; 
  120.         menuItem -ob true 
  121.             -command ("hyperBookmarkAddCallback " + $editor + " first")
  122.             hyperBookmarkAddMenuOBItem; 
  123.         menuItem 
  124.             -l "Delete Bookmark" 
  125.             -command ("hyperBookmarkDeleteCallback " + $editor)
  126.             hyperBookmarkDeleteMenuItem;
  127.         menuItem 
  128.             -l "Delete All Bookmarks" 
  129.             -command ("hyperBookmarkDeleteAllCallback " + $editor)
  130.             hyperBookmarkDeleteAllMenuItem;
  131.         menuItem 
  132.             -l "Rename Bookmark..." 
  133.             -command ("hyperBookmarkRenameCallback " + $editor)
  134.             hyperBookmarkRenameMenuitem;
  135. }
  136.  
  137.  
  138. global proc hyperBookmarkUpdate(string $editor) 
  139. {
  140.     global string $hyperBookmarks[];
  141.  
  142.     if (`window -exists hyperBookmarkWindow`) {
  143.         if(`about -mac`) {
  144.             setParent
  145.                 ("hyperBookmarkWindow|hyperBookmarkWindow|" + 
  146.                  "hyperBookmarkEditorForm|" + 
  147.                  "hyperBookmarkListForm");
  148.         } else {
  149.             setParent
  150.                 ("hyperBookmarkWindow|" + 
  151.                  "hyperBookmarkEditorForm|" + 
  152.                  "hyperBookmarkListForm");
  153.         }     
  154.         if (`textScrollList -exists sl`){
  155.             deleteUI sl;
  156.         }
  157.  
  158.         formLayout -e -visible false hyperBookmarkListForm;
  159.  
  160.         textScrollList -height 100 
  161.             -allowMultiSelection no 
  162.             -allowAutomaticSelection yes 
  163.             sl;
  164.  
  165.         formLayout -e
  166.             -attachForm sl top 0 
  167.             -attachForm sl left 0 
  168.             -attachForm sl bottom 0
  169.             -attachForm sl right 0 
  170.             hyperBookmarkListForm;
  171.         $hyperBookmarks = `listConnections hyperGraphInfo.bookmarks`;
  172.         string $description;
  173.  
  174.         for ($item in $hyperBookmarks) {
  175.             $description = `getAttr ($item + ".description")`;
  176.             if ($description == "")
  177.                 $description = $item;
  178.  
  179.             textScrollList -e -a $description sl;
  180.         }
  181.  
  182.         textScrollList -e 
  183.             -selectCommand ("hyperBookmarkSelectCallback " + $editor)
  184.             sl;
  185.         textScrollList -e 
  186.             -doubleClickCommand ("hyperBookmarkRenameCallback " + $editor)
  187.             sl;
  188.         textScrollList -e 
  189.             -deleteKeyCommand ("hyperBookmarkDeleteCallback " + $editor)
  190.             sl;
  191.  
  192.         formLayout -e -visible true hyperBookmarkListForm;
  193.  
  194.         setParent ..;
  195.     }
  196. }
  197.  
  198.  
  199. global proc hyperBookmarkSelectCallback(string $editor)
  200. //
  201. // Callback for selecting hyperGraph bookmarks.
  202. //
  203. {
  204.     global string $hyperBookmarks[];
  205.     int $item[1] = `textScrollList -q -selectIndexedItem sl`;
  206.     hyperGraph -e -restoreBookmark
  207.         $hyperBookmarks[$item[0]-1] $editor;
  208. }
  209.  
  210.  
  211. global proc hyperBookmarkRenameCallback(string $editor)
  212. //
  213. // Callback for renaming hyperGraph bookmarks.
  214. // Check first whether something is selected
  215. //
  216. {
  217.     string $selectedItem[] = `textScrollList -q -si sl`;
  218.     if (`size($selectedItem)` == 0) {
  219.         return;
  220.     } 
  221.     else {
  222.         global string $hyperBookmarks[];
  223.         string $description;
  224.     
  225.         int $item[1] = `textScrollList -q -selectIndexedItem sl`;
  226.         
  227.         $description = 
  228.             `getAttr ($hyperBookmarks[$item[0]-1] + ".description")`;
  229.     
  230.         string $result = `promptDialog
  231.             -title "Rename Bookmark"
  232.             -message "Rename Bookmark:"
  233.             -text (textScrollList ("-q", "-selectItem", "sl"))
  234.             -defaultButton "OK"
  235.             -button "OK" 
  236.             -button "Cancel"`;
  237.         if ($result == "OK") {
  238.             setAttr ($hyperBookmarks[$item[0]-1] + ".description")
  239.                 -type "string"
  240.                 `promptDialog -q -tx`;
  241.         }
  242.         hyperBookmarkUpdate($editor);
  243.     }
  244. }
  245.  
  246.  
  247. global proc hyperBookmarkDeleteCallback(string $editor)
  248. //
  249. // Callback for deleting hyperGraph bookmarks.
  250. // Check first whether something is selected
  251. //
  252. {
  253.     string $selectedItem[] = `textScrollList -q -si sl`;
  254.     if (`size($selectedItem)` == 0) {
  255.         return;
  256.     } 
  257.     else {
  258.         global string $hyperBookmarks[];
  259.     
  260.         int $item[1] = `textScrollList -q -selectIndexedItem sl`;
  261.         textScrollList -e -rii $item[0] sl;
  262.         hyperGraph -e -deleteBookmark $hyperBookmarks[$item[0]-1]
  263.             $editor;
  264.         hyperBookmarkUpdate($editor);
  265.     }
  266. }
  267.  
  268. global proc hyperBookmarkDeleteAllCallback(string $editor)
  269. //
  270. // Callback for deleting all hyperGraph bookmarks.
  271. //
  272. {
  273.     string $allItems[] = `textScrollList -q -ai sl`;
  274.     int $numItems = size($allItems);
  275.     if ($numItems == 0) {
  276.         return;
  277.     } 
  278.     else {
  279.         global string $hyperBookmarks[];
  280.         textScrollList -e -ra sl;
  281.         for ($i = $numItems-1; $i >= 0; $i--) {
  282.             hyperGraph -e -deleteBookmark $hyperBookmarks[$i] $editor;
  283.         }
  284.         hyperBookmarkUpdate($editor);
  285.     }
  286. }
  287.  
  288.  
  289. global proc hyperBookmarkAddCallback(string $editor, string $renameWhen)
  290. //
  291. // Callback for adding hyperGraph bookmarks.
  292. //
  293. {
  294.     string $newBookmarkName;
  295.     string $newBookmark;
  296.  
  297.     if ($renameWhen == "first"){
  298.         string $result = `promptDialog
  299.             -title "Name Bookmark"
  300.             -message "Name Bookmark:"
  301.             -text "Bookmark Name"
  302.             -defaultButton "OK"
  303.             -button "OK" 
  304.             -button "Cancel"`;
  305.         if ($result == "OK") {
  306.             $newBookmarkName = `promptDialog -q -tx`;
  307.             hyperGraph -e -addBookmark $editor;
  308.             $newBookmark = 
  309.                 `hyperGraph -q -bookmarkName $editor`;
  310.             setAttr ($newBookmark + ".description") 
  311.                 -type "string" $newBookmarkName;
  312.             hyperBookmarkUpdate($editor);
  313.         }
  314.     } else {
  315.         hyperGraph -e -addBookmark $editor;
  316.         hyperBookmarkUpdate($editor);
  317.     }
  318. }
  319.  
  320.  
  321.  
  322. global proc hyperBookmarkRenameMenuCallback(string $editor, string $nodeName)
  323. //
  324. // Callback for renaming hyperGraph menuBookmarks.
  325. //
  326. {
  327.     string $userName = 
  328.         `getAttr ($nodeName + ".description")`;
  329.     if ($userName == "") {
  330.         $userName = $nodeName;
  331.     }
  332.     string $result = `promptDialog
  333.         -title "Rename Bookmark"
  334.         -message "Rename Bookmark:"
  335.         -text $userName
  336.         -defaultButton "OK"
  337.         -button "OK" 
  338.         -button "Cancel"`;
  339.     if ($result == "OK") {
  340.         setAttr ($nodeName + ".description")
  341.             -type "string"
  342.             `promptDialog -q -tx`;
  343.     }
  344.     hyperBookmarkUpdate($editor);
  345. }
  346.  
  347.  
  348. global proc hyperBookmarkBuildMenu(string $editor, string $parent)
  349. {
  350.     global string $hyperBookmarks[];
  351.     
  352.     setParent -menu $parent;
  353.  
  354.     menu -e -deleteAllItems $parent;
  355.  
  356.     menuItem -label "Create Bookmark" 
  357.         -command ("hyperBookmarkAddCallback " + $editor + " later")
  358.         saveBMItem;
  359.     menuItem -ob true 
  360.         -command ("hyperBookmarkAddCallback " + $editor + " first");
  361.     menuItem -label "Bookmark Editor..." 
  362.         -command ("hyperViewer " + $editor)
  363.         bookmarkEditor;
  364.     menuItem -divider true;
  365.     
  366.     // Create a menu item for each bookmark
  367.     string $bookmarks[] = `listConnections hyperGraphInfo.bookmarks`;
  368.     string $description;
  369.     string $nodeName;
  370.  
  371.     for ($item in $bookmarks) {
  372.         $nodeName = $item;
  373.         $description = `getAttr ($item + ".description")`;
  374.         
  375.         if ($description == ""){
  376.             $description = $item;
  377.         }
  378.         menuItem -l $description
  379.             -command 
  380.             ("hyperGraph -e -restoreBookmark " + $item + " " + $editor);
  381.         menuItem -ob true 
  382.             -command ("hyperBookmarkRenameMenuCallback " 
  383.                       + $editor + " " + $nodeName);    
  384.     }
  385. }
  386.  
  387.  
  388.